package apibasej.db.transaction;

import apibasej.basic.config.CommonProperties;
import apibasej.basic.exception.APIBaseException;
import apibasej.db.to.StatementValues;


/**
 * http://code.google.com/p/apibasej/
 * 
 * @author Julio Azevedo Lessa - apibasej@gmail.com
 * 
 */
@SuppressWarnings("serial")
public class UtilDBException extends APIBaseException implements CommonProperties{
	

	public UtilDBException(String message, StatementValues statementQuery, StatementValues statementUpdate) {
		super(message+genInfoSqls(statementQuery, statementUpdate));
		//genInfoSqls(statementQuery, statementUpdate);
	}

	public UtilDBException(String message, Throwable cause, StatementValues statementQuery, StatementValues statementUpdate) {
		super(message+genInfoSqls(statementQuery, statementUpdate), cause);
		//genInfoSqls(statementQuery, statementUpdate);
	}
	
	public UtilDBException(String message) {
		super(message);
	}
	public UtilDBException(String message, Throwable cause) {
		super(message, cause);
	}
	
	
	private static String genInfoSqls(StatementValues statementQuery, StatementValues statementUpdate){
		try{
			String r = "";
			if(statementQuery!=null){
				r += " [STATEMENT_QUERY="+statementQuery.getSqlInfo()+"]";
			}
			if(statementUpdate!=null){
				r += " [STATEMENT_UPDATE="+statementUpdate.getSqlInfo()+"]";
			}
			return r;
			//return "\n"+(statementQuery!=null?statementQuery.getSqlInfo():null)+"\n"+(statementUpdate!=null?statementUpdate.getSqlInfo():"");
			//if(lastSqls!=null && lastSqls.trim().length()>0){
			//	c.getProp(CommonProperties.LOGGER).log(Level.SEVERE,"LAST SQLS: "+lastSqls);
			//}
		}catch (Exception e2) {
			return " [ERROR_ON_GET_INFO_SQLS"+e2+"]";
		}
	}
	
}
